package com.liliudong.pinkyponk.biz.sys.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liliudong.pinkyponk.biz.sys.entity.SysUserOrg;
import com.liliudong.pinkyponk.biz.sys.mapper.SysUserOrgMapper;
import com.liliudong.pinkyponk.biz.sys.service.SysUserOrgService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * SysUserOrgService
 *
 * @author liliudong
 * @date 2022-06-03 22:44
 **/
@Service
public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUserOrg> implements
        SysUserOrgService {

    @Override
    public void saveBatchByUserId(Long userId, List<Integer> orgIds) {
        List<SysUserOrg> list = orgIds.stream()
                .map(orgId -> SysUserOrg.builder().orgId(orgId).userId(userId).build())
                .collect(Collectors.toList());
        this.saveBatch(list);
    }

    @Override
    public void removeByUserId(Long userId) {
        baseMapper.delete(Wrappers.<SysUserOrg>lambdaQuery().eq(SysUserOrg::getUserId, userId));
    }
}
